import vue from 'vue'
import vuex from 'vuex'
vue.use(vuex)
//引入封装好的模块
import menu from './modules/meun'
import role from './modules/role'
import user from './modules/manger'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import banner from './modules/banner'
import member from './modules/member'
import seck from './modules/seck'
export default new vuex.Store({
    state: {
        //用户信息
        //在这去处存储的值
        userInfo:sessionStorage.getItem('userInfo') ? JSON.parse(sessionStorage.getItem('userInfo')):null
    },
    getters:{
        //返回给视图一个用户信息
        getUserInfo(state){
            return state.userInfo
        }
    },
    mutations: {
        CHANG_USERINFO(state,payload){
            if(payload){
                state.userInfo=payload
                //如果有参数，我们把参数存储到会话存储中
                sessionStorage.setItem('userInfo',JSON.stringify(payload))
            }else{
                //如果退出，我就删除本地存储的内容
                sessionStorage.removeItem('userInfo')
            }
        }
    },
    actions: {
        changeUserInfoAction({commit},payload){
            commit('CHANG_USERINFO',payload)
        }
    },
    modules: {
        menu,
        role,
        user,
        cate,
        specs,
        goods,
        banner,
        member,
        seck
    }
})